package com.wzh.ojbackendquestionservice.config;

import com.wzh.ojCommon.constant.RabbitMqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 消息队列解耦 声明题目提交队列
 */
@Configuration
public class QuestionSubmitRabbitMqConfig {


    /**
     * durable:队列持久化，即使rabbitMq重启，此队列依然存在
     * @return
     */
    @Bean
    public Queue questionSubmitQueue(){
        return new Queue(RabbitMqConstant.QUESTION_SUBMIT_QUEUE,true,false,false,null);
    }


    @Bean
    public Exchange  questionSubmitExchange(){
        return new DirectExchange(RabbitMqConstant.QUESTION_SUBMIT_EXCHANGE,true,false);
    }

    /**
     * 交换机和普通队列绑定
     * @return
     */
    @Bean
    public Binding questionSubmitBiding(){
        return new Binding(RabbitMqConstant.QUESTION_SUBMIT_QUEUE,Binding.DestinationType.QUEUE,RabbitMqConstant.QUESTION_SUBMIT_EXCHANGE,RabbitMqConstant.QUESTION_SUBMIT_ROUTE_KEY,null);
    }

}
